<extend name="Base:main" />
<block name="title">
<title>蔬菜外卖 - 配送时间管理</title>
</block>
<block name="main-content">
<div class="row">
	<div class="box col-md-12">
		<div class="box-inner">
			<div class="box-header well" data-original-title="">
				<h2>
					<i class="glyphicon glyphicon-user"></i>配送区域管理
				</h2>

				<div class="box-icon">
					<a href="#" class="btn btn-add btn-round btn-default"><i
						class="glyphicon glyphicon-plus"></i></a> <a href="#"
						class="btn btn-minimize btn-round btn-default"><i
						class="glyphicon glyphicon-chevron-up"></i></a> <a href="#"
						class="btn btn-close btn-round btn-default"><i
						class="glyphicon glyphicon-remove"></i></a>
				</div>
			</div>
			<div class="box-content">
				<div class="alert alert-info">对配送区域进行查看以及管理</div>
				<div class="loading col-sm-12 center">
					<img src="__PUBLIC__/img/ajax-loaders/ajax-loader-5.gif">
				</div>
				<table
					class="table table-striped table-bordered bootstrap-datatable datatable responsive"
					id="orderlist" style="display: none;">
					<thead>
						<tr>
							<th>序号</th>
							<th>配送起始时间</th>
							<th>配送结束时间</th>
							<th>配送类型</th>
							<th>配送状态</th>
							<th>操作</th>
						</tr>
					</thead>
					<tbody>
						<foreach name="list" item="v">
						<tr id="row_{$v.id}">
							<td><if condition="($_GET['p'] eq 0)">{++$i}<else />{++$i +
								($_GET['p']-1) * 17}</if></td>
							<td id="stime_{$v.id}">{$v.stime}</td>
							<td id="etime_{$v.id}">{$v.etime}</td>
							<td id="type_{$v.id}"><if condition="$v['type'] eq 1">今日配送<else />明日配送</if>
							</td>
							<td>
								<input id="{$v.id}" class="switch" type="checkbox" <?php if($v['status']) echo "checked"; ?>/>
							<td>
								<button class="btn btn-primary btn-xs"
									onclick="edit('{$v.id}');" data-toggle="modal">
									<i class="glyphicon glyphicon-edit icon-white"></i>
								</button>
								<button class="btn btn-danger btn-xs btn-delete" id="{$v.id}">
									<i class="glyphicon glyphicon-trash icon-white"></i>
								</button>
							</td>
						</tr>
						</foreach>
					</tbody>
				</table>
			</div>
			<!-- end box-content -->
		</div>
		<!-- end box-inner -->
	</div>
	<!-- end box -->
</div>
<!-- end row --> <!-- 添加菜单弹出框 -->
<div class="modal fade" id="myAddModal" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog" style="width: 900px;">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"
					aria-hidden="true">&times;</button>
				<h4 class="modal-title" id="myModalLabel">添加配送时间</h4>
			</div>
			<div class="modal-body">
				<form class="form-horizontal style-form" id="form_add"
					action="__APP__/Admin/System/addInfo" method="post">
					<input type="hidden" name="action" value="orderTime">
					<div class="form-group">
						<label class="col-sm-2 control-label">配送类型：</label>
						<div class="col-sm-10">
							<select id="type" name="type" class="form-control">
								<option value="1" selected="selected">今日配送</option>
								<option value="2">明日配送</option>
							</select>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label">配送开始时间：</label>
						<div class="col-sm-10">
							<input class="form-control" type="time" name="stime"
								id="add_stime">
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label">配送结束时间：</label>
						<div class="col-sm-10">
							<input class="form-control" type="time" name="etime"
								id="add_etime">
						</div>
					</div>
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
				<button type="button" class="btn btn-danger">确定</button>
			</div>
		</div>
	</div>
</div>
<!-- 编辑菜单弹出框 -->
<div class="modal fade" id="myEditModal" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog" style="width: 900px;">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"
					aria-hidden="true">&times;</button>
				<h4 class="modal-title" id="myModalLabel">修改配送时间</h4>
			</div>
			<div class="modal-body">
				<form class="form-horizontal style-form" method="get">
					<div class="form-group">
						<label class="col-sm-2 control-label">配送类型：</label>
						<div class="col-sm-10">
							<select id="update_type" name="type" class="form-control">
								<option value="1" selected="selected">今日配送</option>
								<option value="2">明日配送</option>
							</select>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label">配送开始时间：</label>
						<div class="col-sm-10">
							<input class="form-control" type="time" name="stime"
								id="update_stime">
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label">配送结束时间：</label>
						<div class="col-sm-10">
							<input class="form-control" type="time" name="etime"
								id="update_etime">
						</div>
					</div>
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
				<button type="button" class="btn btn-danger">确定</button>
			</div>
		</div>
	</div>
</div>

<!-- 删除菜单弹出框 -->
<div class="modal fade" id="myDeleteModal" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog" style="width: 900px;">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"
					aria-hidden="true">&times;</button>
				<h4 class="modal-title" id="myModalLabel">删除配送时间</h4>
			</div>
			<div class="modal-body">
				<p id="sccontent" name="sccontent">你确定要删除吗？该操作不可恢复！</p>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
				<button type="button" class="btn btn-danger">确定</button>
			</div>
		</div>
	</div>
</div>
</block>
<block name="js-content"> <script type="text/javascript">
var action = "orderTime";
var deleteUrl="__APP__/Admin/System/deleteInfo";
var getInfo="__APP__/Admin/System/getInfo";
var editUrl="__APP__/Admin/System/updateInfo";
var addUrl="__APP__/Admin/System/addInfo";
$(document).ready(function () {
	$('input[class="switch"]').on('switchChange.bootstrapSwitch', function(event, state) {
//   	  console.log(this); // DOM element
//   	  console.log(event); // jQuery event
//   	  console.log(state); // true | false
  		var id = this.id;
  		var status = 0;
  		if(state){
  			status = 1;
  	  	}
	  	$.post(editUrl,{id:id,action:action,status:status},function(data){
		  	if(data){
			  	console.log("修改成功");
			}else{
				console.log("修改失败");
			}
	  	});
  	});
});
//打开编辑的modal.
function  edit(id)
{
	$(".btn-danger").attr('id',id);
	$.post(getInfo,{id:id,action:action},function(data){
// 		console.log(data);
		$("#update_type").val(data['type']);
		$("#update_stime").val(data['stime']);
		$("#update_etime").val(data['etime']);
	});
	$("#myEditModal").modal('show');
}
$('#myEditModal').on('click','button.btn-danger',function (a){
// 		console.log(data);
	var id = $(".btn-danger").attr('id');
	var type = $("#update_type").val();
	var stime = $("#update_stime").val();
	var etime = $("#update_etime").val();
	$.post(editUrl,{id:id,action:action,type:type,stime:stime,etime:etime},function(data){
		if(data){
			alert('修改成功');
			$("#stime_"+id).html(stime);
			$("#etime_"+id).html(etime);
			console.log(type);
			var s_type = "";
			if(type == 1){
				s_type = "今日配送";
			}else{
				s_type = "明日配送";
			}
			$("#type_"+id).html(s_type);
			$("#myEditModal").modal('hide');
		}else{
			alert('修改失败');
		}
	});
});
  </script> </block>
